package ms;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Composition {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int stringLength, unAdjacent;
		String string;
		List<String> pattern = new ArrayList<String>();
		String temp;
		while(scanner.hasNext()){
			stringLength = scanner.nextInt();
			scanner.nextLine();
			string = scanner.nextLine();
			unAdjacent = scanner.nextInt();
			scanner.nextLine();
			pattern.clear();
			for (int i = 0; i < unAdjacent; i++) {
				temp = scanner.nextLine();
				pattern.add(temp);
				pattern.add(temp.charAt(1)+ "" + temp.charAt(0));
			}
			getMaxLength(string.toCharArray(), pattern);
		}
		scanner.close();
	}
	public static void getMaxLength(char[] string,  List<String> pattern){
		//res[i][j]表示0...i的子串中留下的最后一个字母是j时的最大长度
		int[][] res = new int[string.length + 1][26];
		for(int j = 0; j < res[0].length; j++){
		}
		res[1][string[0] - 'a'] = 1; 
		for(int i = 2; i < res.length; i++){
			int maxVal = 1;
			for(int j = 0; j < res[0].length; j++){
				if(j != string[i - 1] - 'a'){
					res[i][j] = res[i - 1][j];
					continue;
				}
				for (int k = 0; k < res[0].length; k++) {
					if(res[i - 1][k] == 0){
						continue;
					}
//					System.out.println("串: " + (char)(k + 'a') + string[i - 1]);
					if (pattern.contains((char) (k + 'a') + "" + (string[i - 1]))) {
//						System.out.println("跳出串: " + (char)(k + 'a') + string[i - 1]);
						continue;
					}
					if(res[i - 1][k] + 1 > maxVal){
						maxVal = res[i - 1][k] + 1;
					}
				}
				res[i][string[i - 1] - 'a'] = maxVal;
			}
		}
//		for (int i = 0; i < res.length; i++) {
//			for (int j = 0; j < res[0].length; j++) {
//				System.out.print(res[i][j] + " ");
//			}
//			System.out.println();
//		}
		int max = 0;
		for (int j = 0; j < res[0].length; j++) {
			max = Math.max(max, res[res.length - 1][j]);
		}
		System.out.println(string.length - max);
	}
}
